#include <iostream>
using namespace std;
const int maxn = 130;
int T,n,a[maxn],ans;bool b[maxn];
void check(int x){
    for(int i = 0;i<n;i++){
        b[i]=(x>>i)&1;
    }
    int cnt = 0;
    for(int i = 1;i<=n;i++){
        for(int j = i-1;j>=1;j--){
            if(b[i]==b[j]){
                if(a[i]==a[j]) cnt += a[i];
                break;
            }
            
        }
    }
    if(cnt>ans)ans = cnt;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> T;
    while(T--){
        ans = 0;
        cin >> n;
        for(int i = 1;i<=n;i++) b[i] = false;
        for(int i = 1;i<=n;i++){
            cin >> a[i];
        }
        for(int i = 0;i<=((int)1<<(int)n)-(int)1;i++){
            check(i);
        }
        cout << ans << endl;
    }
    return 0;
}

//Good luck CSP-S2 2024 
//RP++
//Wel and doowzs blesses me.
